package perfumecabinet

import (
	"context"

	"mall/common/jwt"
	"mall/common/resultx"
	"mall/service/backend/common/utils/pointy"
	"mall/service/forum/api/internal/svc"
	"mall/service/forum/api/internal/types"
	"mall/service/forum/rpc/forumclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeletePerfumeCabinetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 移出香水柜香水柜
func NewDeletePerfumeCabinetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePerfumeCabinetLogic {
	return &DeletePerfumeCabinetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeletePerfumeCabinetLogic) DeletePerfumeCabinet(req *types.IDsReq) (resp *types.BaseMsgResp, err error) {
	userId := jwt.GetUserId(l.ctx)
	if userId == 0 {
		return nil, resultx.NewErrCode(resultx.TOKEN_EXPIRE_ERROR)
	}
	if len(req.Ids) == 0 {
		return nil, resultx.StatusError(resultx.FORUM_PERFUME_CABINET_ID_REQUIRED, "")
	}
	res, err := l.svcCtx.ForumRpc.DeletePerfumeCabinet(l.ctx, &forumclient.DeletePerfumeCabinetReq{
		Ids:    req.Ids,
		UserId: pointy.GetPointer(userId),
	})
	if err != nil {
		return nil, err
	}
	return &types.BaseMsgResp{
		Msg: res.Msg,
	}, nil
}
